package com.fei.service;

import com.fei.bean.MusicBean;
import com.fei.mapper.BroadcastMapper;
import com.fei.mapper.MusicMapper;
import com.fei.mapper.SongListMusicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Service
public class MusicServiceImpl implements MusicService{

    @Autowired
    MusicMapper musicMapper;
    @Autowired
    FileService fileService;
    @Autowired
    SongListMusicMapper songListMusicMapper;
    @Autowired
    BroadcastMapper broadcastMapper;

    @Override
    public List<MusicBean> selectOneSingerIdService(int singer_id) {
        return musicMapper.selectOneSingerId(singer_id);
    }

    @Override
    public MusicBean selectOneIdService(int id) {
        return musicMapper.selectOneId(id);
    }


    @Override
    public int insertMusicSingerService(MusicBean music) {
        return musicMapper.insertMusicSinger(music);
    }

    @Override
    public Boolean ValidSongTitleService(String song_title) {
        int num = musicMapper.ValidSongTitle(song_title);
        if (num == 0){
            return true;
        }
        return false;
    }

    @Override
    public int deleteMusicOneIdService(int id) {
//        删除对应的歌单中的数据
        songListMusicMapper.deleteOneMusicId(id);
//        删除对应的用户歌单信息
        broadcastMapper.deleteOneMusicId(id);
        return musicMapper.deleteMusicOneId(id);
    }

    @Override
    public int deleteSingerAllService(int singer_id) {
        List<Integer> musicId = musicMapper.selectOneSingerIdGetMusicId(singer_id);
        if (musicId != null){
            for (int i = 0;i<musicId.size();i++){
                //删除用户歌单
                broadcastMapper.deleteOneMusicId(musicId.get(i));
            }
        }
        //删除歌单中的歌曲信息
        songListMusicMapper.deleteOneSingerId(singer_id);
        return musicMapper.deleteSingerAll(singer_id);
    }

    public MusicMapper getMusicMapper() {
        return musicMapper;
    }

    public void setMusicMapper(MusicMapper musicMapper) {
        this.musicMapper = musicMapper;
    }
}
